<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: pico_flash</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.1.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('group__pico__flash.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">pico_flash<div class="ingroups"><a class="el" href="group__high__level.html">High Level APIs</a></div></div></div>
</div><!--header-->
<div class="contents">

<p>High level flash API.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga2ad3247806ca16dec03e655eaec1775f"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a> (void)</td></tr>
<tr class="memdesc:ga2ad3247806ca16dec03e655eaec1775f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize a core such that the other core can lock it out during <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a>.  <a href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">More...</a><br /></td></tr>
<tr class="separator:ga2ad3247806ca16dec03e655eaec1775f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaed14b762cb5fd483995bd36fc8ad338d"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">flash_safe_execute_core_deinit</a> (void)</td></tr>
<tr class="memdesc:gaed14b762cb5fd483995bd36fc8ad338d"><td class="mdescLeft">&#160;</td><td class="mdescRight">De-initialize work done by <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a>.  <a href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">More...</a><br /></td></tr>
<tr class="separator:gaed14b762cb5fd483995bd36fc8ad338d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga679076dc10c5beb73d5f1abdb52d6735"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> (void(*func)(void *), void *param, uint32_t enter_exit_timeout_ms)</td></tr>
<tr class="memdesc:ga679076dc10c5beb73d5f1abdb52d6735"><td class="mdescLeft">&#160;</td><td class="mdescRight">Execute a function with IRQs disabled and with the other core also not executing/reading flash.  <a href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">More...</a><br /></td></tr>
<tr class="separator:ga679076dc10c5beb73d5f1abdb52d6735"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaee44bd9bc42463f0521535825e8d90b2"><td class="memItemLeft" align="right" valign="top"><a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">get_flash_safety_helper</a> (void)</td></tr>
<tr class="memdesc:gaee44bd9bc42463f0521535825e8d90b2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Internal method to return the flash safety helper implementation.  <a href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">More...</a><br /></td></tr>
<tr class="separator:gaee44bd9bc42463f0521535825e8d90b2"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p >High level flash API. </p>
<p >Flash cannot be erased or written to when in XIP mode. However the system cannot directly access memory in the flash address space when not in XIP mode.</p>
<p >It is therefore critical that no code or data is being read from flash while flash is been written or erased.</p>
<p >If only one core is being used, then the problem is simple - just disable interrupts; however if code is running on the other core, then it has to be asked, nicely, to avoid flash for a bit. This is hard to do if you don't have complete control of the code running on that core at all times.</p>
<p >This library provides a <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> method which calls a function back having successfully gotten into a state where interrupts are disabled, and the other core is not executing or reading from flash.</p>
<p >How it does this is dependent on the supported environment (Free RTOS SMP or pico_multicore). Additionally the user can provide their own mechanism by providing a strong definition of <a class="el" href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">get_flash_safety_helper()</a>.</p>
<p >Using the default settings, flash_safe_execute will only call the callback function if the state is safe otherwise returning an error (or an assert depending on PICO_FLASH_ASSERT_ON_UNSAFE).</p>
<p >There are conditions where safety would not be guaranteed:</p>
<ol type="1">
<li>FreeRTOS smp with <code>configNUM_CORES=1</code> - FreeRTOS still uses pico_multicore in this case, so <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> cannot know what the other core is doing, and there is no way to force code execution between a FreeRTOS core and a non FreeRTOS core.</li>
<li>FreeRTOS non SMP with pico_multicore - Again, there is no way to force code execution between a FreeRTOS core and a non FreeRTOS core.</li>
<li>pico_multicore without <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init()</a> having been called on the other core - The <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> method does not know if code is executing on the other core, so it has to assume it is. Either way, it is not able to intervene if <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init()</a> has not been called on the other core.</li>
</ol>
<p >Fortunately, all is not lost in this situation, you may:</p>
<ul>
<li>Set PICO_FLASH_ASSUME_CORE0_SAFE=1 to explicitly say that core 0 is never using flash.</li>
<li>Set PICO_FLASH_ASSUME_CORE1_SAFE=1 to explicitly say that core 1 is never using flash. </li>
</ul>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga679076dc10c5beb73d5f1abdb52d6735" name="ga679076dc10c5beb73d5f1abdb52d6735"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga679076dc10c5beb73d5f1abdb52d6735">&#9670;&nbsp;</a></span>flash_safe_execute()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int flash_safe_execute </td>
          <td>(</td>
          <td class="paramtype">void(*)(void *)&#160;</td>
          <td class="paramname"><em>func</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>param</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>enter_exit_timeout_ms</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Execute a function with IRQs disabled and with the other core also not executing/reading flash. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">func</td><td>the function to call </td></tr>
    <tr><td class="paramname">param</td><td>the parameter to pass to the function </td></tr>
    <tr><td class="paramname">enter_exit_timeout_ms</td><td>the timeout for each of the enter/exit phases when coordinating with the other core</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>PICO_OK on success (the function will have been called). PICO_ERROR_TIMEOUT on timeout (the function may have been called). PICO_ERROR_NOT_PERMITTED if safe execution is not possible (the function will not have been called). PICO_ERROR_INSUFFICIENT_RESOURCES if the method fails due to dynamic resource exhaustion (the function will not have been called) </dd></dl>
<dl class="section note"><dt>Note</dt><dd>if PICO_FLASH_ASSERT_ON_UNSAFE is 1, this function will assert in debug mode vs returning PICO_ERROR_NOT_PERMITTED </dd></dl>

</div>
</div>
<a id="gaed14b762cb5fd483995bd36fc8ad338d" name="gaed14b762cb5fd483995bd36fc8ad338d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaed14b762cb5fd483995bd36fc8ad338d">&#9670;&nbsp;</a></span>flash_safe_execute_core_deinit()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool flash_safe_execute_core_deinit </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>De-initialize work done by <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a>. </p>
<dl class="section return"><dt>Returns</dt><dd>true on success </dd></dl>

</div>
</div>
<a id="ga2ad3247806ca16dec03e655eaec1775f" name="ga2ad3247806ca16dec03e655eaec1775f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2ad3247806ca16dec03e655eaec1775f">&#9670;&nbsp;</a></span>flash_safe_execute_core_init()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool flash_safe_execute_core_init </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize a core such that the other core can lock it out during <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a>. </p>
<dl class="section note"><dt>Note</dt><dd>This is not necessary for FreeRTOS SMP, but should be used when launching via <a class="el" href="group__pico__multicore.html#ga46ea5e2efc181aba1d4d1de06a375c59">multicore_launch_core1</a> </dd></dl>
<dl class="section return"><dt>Returns</dt><dd>true on success; there is no need to call <a class="el" href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">flash_safe_execute_core_deinit()</a> on failure. </dd></dl>

</div>
</div>
<a id="gaee44bd9bc42463f0521535825e8d90b2" name="gaee44bd9bc42463f0521535825e8d90b2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaee44bd9bc42463f0521535825e8d90b2">&#9670;&nbsp;</a></span>get_flash_safety_helper()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> * get_flash_safety_helper </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Internal method to return the flash safety helper implementation. </p>
<p >Advanced users can provide their own implementation of this function to perform different inter-core coordination before disabling XIP mode.</p>
<dl class="section return"><dt>Returns</dt><dd>the <a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>